﻿namespace Devonline.Entity;

/// <summary>
/// 采购订单
/// </summary>
[Table("purchase_order"), DisplayName("采购订单")]
public class PurchaseOrder : PurchaseOrder<string>, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 供应商
    /// </summary>
    public virtual Supplier? Supplier { get; set; }
    /// <summary>
    /// 采购订单明细
    /// </summary>
    public virtual ICollection<PurchaseOrderDetail>? Details { get; set; }
    /// <summary>
    /// 采购订单支付记录
    /// </summary>
    public virtual ICollection<PurchaseOrderPaymentRecord>? PaymentRecords { get; set; }
}

/// <summary>
/// 采购订单
/// </summary>
[Table("purchase_order"), DisplayName("采购订单")]
public abstract class PurchaseOrder<TKey> : EntitySetWithCreateAndUpdate<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey>, IEntitySetWithCreateAndUpdate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 供应商
    /// </summary>
    [Column("supplier_id"), MaxLength(36), DisplayName("供应商"), Required, Excel]
    public virtual string SupplierId { get; set; } = null!;
    /// <summary>
    /// 订单号
    /// </summary>
    [Column("order_number"), Required, MaxLength(36), DisplayName("订单号")]
    public virtual string OrderNumber { get; set; } = null!;
    /// <summary>
    /// 下单时间
    /// </summary>
    [Column("order_time"), DisplayName("下单时间"), Excel]
    public virtual DateTime OrderTime { get; set; }
    /// <summary>
    /// 订单金额
    /// </summary>
    [Column("amount", TypeName = "decimal(18,2)"), DisplayName("订单金额"), Excel]
    public virtual decimal Amount { get; set; }
}

/// <summary>
/// 采购订单明细
/// </summary>
[Table("purchase_order_detail"), DisplayName("采购订单明细")]
public class PurchaseOrderDetail : EntitySetWithCreate, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 采购订单
    /// </summary>
    public virtual PurchaseOrder? Order { get; set; }
    /// <summary>
    /// 货品
    /// </summary>
    public virtual Product? Product { get; set; }
}

/// <summary>
/// 采购订单明细
/// </summary>
[Table("purchase_order_detail"), DisplayName("采购订单明细")]
public abstract class PurchaseOrderDetail<TKey> : EntitySetWithCreate<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 采购订单编号
    /// </summary>
    [Column("order_id"), Required, MaxLength(36), DisplayName("采购订单编号"), Excel]
    public virtual string OrderId { get; set; } = null!;
    /// <summary>
    /// 货品编号
    /// </summary>
    [Column("product_id"), Required, MaxLength(36), DisplayName("货品编号"), Excel]
    public virtual string ProductId { get; set; } = null!;
    /// <summary>
    /// 订单货品品质
    /// </summary>
    [Column("quality"), MaxLength(128), DisplayName("货品品质"), Excel]
    public virtual string? Quality { get; set; }
    /// <summary>
    /// 采购价
    /// </summary>
    [Column("price", TypeName = "decimal(18,2)"), DisplayName("采购价"), Excel]
    public virtual decimal Price { get; set; }
    /// <summary>
    /// 数量
    /// </summary>
    [Column("count", TypeName = "decimal(18,2)"), DisplayName("数量"), Excel]
    public virtual decimal Count { get; set; }
}

/// <summary>
/// 采购订单支付记录
/// </summary>
[Table("purchase_order_payment_record"), DisplayName("采购订单支付记录")]
public class PurchaseOrderPaymentRecord : PurchaseOrderPaymentRecord<string>, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 交易账户
    /// </summary>
    public virtual Account? Account { get; set; }
    /// <summary>
    /// 采购订单
    /// </summary>
    public virtual PurchaseOrder? Order { get; set; }
}

/// <summary>
/// 采购订单支付记录
/// </summary>
[Table("purchase_order_payment_record"), DisplayName("采购订单支付记录")]
public abstract class PurchaseOrderPaymentRecord<TKey> : AccountRecord<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible { }